package org.linitly.util;

import org.apache.commons.lang3.StringUtils;

/**
 * @author: linxiunan
 * @date: 2021/6/2 17:54
 * @descrption:
 */
public class StringUtil {

    private static final char UNDER_SCORE = '_';
    private static final char UNDER_LINE = '-';

    public static String getMainClassNamePrefix(String projectName) {

        if (StringUtils.isBlank(projectName)) return "";
        int len = projectName.length();
        StringBuilder sb = new StringBuilder(len);
        // 首字母大写
        sb.append(Character.toUpperCase(projectName.charAt(0)));
        for (int i = 1; i < len; i++) {
            char c = projectName.charAt(i);
            if (c == UNDER_SCORE || c == UNDER_LINE) {
                if (++i < len) {
                    sb.append(Character.toUpperCase(projectName.charAt(i)));
                }
            } else {
                sb.append(c);
            }
        }
        return sb.toString();
    }
}
